package pw.archipelag.loaderGame.loaderShow {
	import base.loader.show.LoaderProgressBar;
	import flash.display.Sprite;
	import flash.text.Font;
	import base.tf.TextFieldUtils;
	import flash.text.TextFormat;
	import flash.events.Event;
	
	public class Progress extends LoaderProgressBar {
		
		[Embed(source = "../!embed/HelveticaNeueLTPro-Roman.otf", fontName="HelveticaNeueLTPro-Roman", mimeType = 'application/x-font', embedAsCFF='false', unicodeRange='U+0020-U+007E, U+0105, U+0119, U+00F3, U+0142, U+017C, U+017a, U+0107, U+015B, U+0144, U+0104, U+0118, U+00D3, U+0141, U+017B, U+0179, U+0106, U+015A, U+0143, U+00A0, U+F0B7')] /*U+0030-U+0039, U+0025*/
		public static const classFontTfPercent: Class;
		
		[Embed(source="../!embed/assetsLoaderGame.swf", symbol="progressBar")]
		public static const classProgressBar: Class;
		
		[Embed(source="../!embed/assetsLoaderGame.swf", symbol="progressBarArrow")]
		public static const classProgressBarArrow: Class;
		
		public static const COLOR: uint = 0x373535;
		public static const MARGIN_Y_PROGRESS_BAR: Number = 250;
		
		private var progressBarArrow: Sprite;
		
		public function Progress(): void {
			Font.registerFont(Progress.classFontTfPercent);
			this.createProgressBarArrow();
			super(this.createMask(), Progress.COLOR, 0, TextFieldUtils.createTextField(new TextFormat("HelveticaNeueLTPro-Roman", 22, Progress.COLOR)), 5, 0);
			this.addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
		}
		
		private function onAddedToStage(e: Event): void {
			this.removeEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
			this.repositionBgAndBar(0, Progress.MARGIN_Y_PROGRESS_BAR);
			this.tfPercent.y = this.bar.y + this.bar.height + 8;
			this.update();
		}
			
		private function createProgressBarArrow(): void {
			this.progressBarArrow = new Progress.classProgressBarArrow();
			this.progressBarArrow.y = Progress.MARGIN_Y_PROGRESS_BAR;
			this.addChild(this.progressBarArrow);
		}
		
		private function createMask(): Sprite {
			var mask: Sprite = new Progress.classProgressBar();
			return mask;
		}
		
		override protected function update(): void {
			super.update();
			this.tfPercent.x = this.bar.x + this.bar.width + this.progressBarArrow.width / 2 - 30 - this.tfPercent.width / 2;
			this.progressBarArrow.x = this.bar.x + this.bar.width - 0.8;
		}
		
	}

}